package com.medusa.aps.business.modules.board.mp.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.medusa.aps.business.model.pagination.Page;
import com.medusa.aps.business.modules.board.model.dto.WorkshopProductionStatisticsDTO;
import com.medusa.aps.business.modules.board.model.input.WorkshopProductionDetailBaseQueryParam;
import com.medusa.aps.business.modules.board.model.input.WorkshopProductionStatisticsParam;
import com.medusa.aps.business.modules.board.model.output.WorkshopProductionDetailVO;
import com.medusa.aps.business.modules.board.model.output.WorkshopProductionEquipmentVO;
import com.medusa.aps.business.modules.board.mp.entity.WorkshopProductionStatistics;
import com.medusa.aps.business.modules.modeling.mp.entity.Equipment;
import com.medusa.aps.business.global.model.o.RangeDate;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * <p>车间生产统计Mapper接口</p>
 * @author An.Yan
 */
public interface IWorkshopProductionStatisticsMapper extends BaseMapper<WorkshopProductionStatistics> {

    /**
     * 查询车间排产统计数据
     * @param queryParam 统计参数
     * @return 与统计参数匹配的统计数据,参考 {@link WorkshopProductionStatisticsDTO}
     */
    List<WorkshopProductionStatisticsDTO> selectPage(@Param("workshopIds") Set<Long> workshopIds, @Param("rangeDate") RangeDate rangeDate);

    /**
     * 分页查询不重复的车间ID
     * @param queryParam 分页参数
     * @return 不重复的车间ID分页数据
     */
    Page<Long> selectNonDuplicatedWorkshopIds(@Param("queryParam") WorkshopProductionStatisticsParam queryParam);

    /**
     * 分页查询车间生产详情数据
     * @param queryParam 分页参数,参考{@link WorkshopProductionDetailBaseQueryParam}
     * @return {@link WorkshopProductionDetailVO}
     */
    Page<WorkshopProductionDetailVO> selectDetailsPage(@Param("queryParam") WorkshopProductionDetailBaseQueryParam queryParam);

    /**
     * 统计给定的车间ID在指定的日期已排产设备数量以及系统可用设备总数
     * @param workshopId 车间ID
     * @param statDate 统计时间
     * @return {@link WorkshopProductionEquipmentVO}集合
     */
    List<WorkshopProductionEquipmentVO> statisticsEquipment(@Param("workshopId") Integer workshopId, @Param("statDate") LocalDate statDate);

    /**
     * 获取系统可用的设备总数
     * @return 可用的设备总数
     */
    List<Equipment> statisticsAvailableEquipment(@Param("workshopIds") List<Long> workshopIds);

    /**
     * 根据workshopID + statDate 查询统计数据
     * @param statisticsEntities 统计数据参数
     * @return 与workshopID + statDate相匹配的统计数据
     */
    List<WorkshopProductionStatistics> selectStatisticsByCondition(@Param("statisticsEntities") List<WorkshopProductionStatistics> statisticsEntities);

    /**
     * 查询不存在的统计数据(key:workshop_id + stat_date)
     * @param statisticsEntities
     * @return workshop_id和stat_date不等于 {@code statisticsEntities}的数据
     */
    List<WorkshopProductionStatistics> selectNonExistentStatisticsData(@Param("statisticsEntities") List<WorkshopProductionStatistics> statisticsEntities);
}
